<?php
require_once 'functions.php';
//首先进行非空排错
if(!isset($_POST['username'])){
    die('name is not define');
}
if(!isset($_POST['password'])){
   
    die('password not define');
}
if(!isset($_POST['email'])){
   
    die('emaiis not define');
}
if(!isset($_POST['qq'])){

    die('qq not define');
}
if(!isset($_POST['phone'])){
   
    die('phone not define');
}
if(!isset($_POST['address'])){
    
    die('address not define');
}

$name=$_POST['username'];
$email=$_POST['email'];
$sex=$_POST['sex'];
$password=$_POST['password'];
$qq=$_POST['qq'];
$phone=$_POST['phone'];
$address=$_POST['address'];


if(empty($name)){
    echo  "<script>alert('name is not empty')</script> ";
    // die('name is empty');
}
if(empty($password)){
    echo  "<script>alert('password is not empty')</script> ";
}
if(empty($email)){
    echo  "<script>alert('email is not empty')</script> ";
}
if(empty($qq)){
    echo  "<script>alert('qq is not empty')</script> ";
}
if(empty($phone)){
    echo  "<script>alert('phone is not empty')</script> ";
}
if(empty($address)){
    echo  "<script>alert('address is not empty')</script> ";
}
//连接数据库
connnetDb();
 
 
//执行类型转换，防止SQL注入
// $age=intval($age);
//插入数据
mysql_query("INSERT INTO usertext(username,email,sex,password,qq,phone,address) VALUES ('$name','$email','$sex','$password','$qq','$phone',$address)");
//返回列表页面
if(mysql_error()){        
    echo "<script>alert('信息完整请重新输入').</script>" ;                          
        header("Location:adduser.html");
}
else{
    header("Location:allusers.php");
}